package cn.elead.chaos.remote.web.system.controller;

import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import cn.elead.chaos.core.enums.BusinessType;
import cn.elead.chaos.excel.ExcelUtil;
import cn.elead.chaos.framework.monitor.operlog.Log;
import cn.elead.chaos.mybatils.web.controller.BaseController;
import cn.elead.chaos.remote.web.system.service.IRemoteMenuService;
import cn.elead.chaos.remote.web.system.domain.SysMenu;
import cn.elead.chaos.remote.web.system.domain.vo.TreeSelect;

/**
 * 菜单权限Controller
 * 
 * @author luopeng
 * @date 2020-02-26 12:59:33
 */
@RestController
@RequestMapping("/remote/system/menu")
public class RemoteMenuController extends BaseController
{
    @Autowired
    private IRemoteMenuService menuService;

    /**
     * 查询菜单权限列表
     */
    @GetMapping("/list")
    @RequiresPermissions("system:menu:list")
    public List<SysMenu> list(SysMenu sysMenu) {
        return menuService.list(sysMenu);
    }

    /**
     * 导出菜单权限列表
     */
    @GetMapping("/export")
    @RequiresPermissions("system:menu:export")
    @Log(title = "菜单权限", businessType = BusinessType.EXPORT)
    public String export(SysMenu sysMenu) {
        List<SysMenu> list = menuService.list(sysMenu);
        ExcelUtil<SysMenu> util = new ExcelUtil<SysMenu>(SysMenu.class);
        return util.exportExcel(list, "menu");
    }

    /**
     * 获取菜单权限详细信息
     */
    @GetMapping(value = "/{menuId}") 
    @RequiresPermissions("system:menu:list")
    public SysMenu getInfo(@PathVariable("menuId") Long menuId) {
       	return menuService.getInfo(menuId);
    }
    
    /**
	 * 获取菜单下拉树列表
	 */
	@GetMapping("/treeselect")
	public List<TreeSelect> treeselect(SysMenu dept) {
		return menuService.treeselect(dept);
	}
	
	/**
	 * 加载对应角色菜单列表树
	 */
	@GetMapping(value = "/roleMenuTreeselect/{roleId}")
	public List<Integer> roleMenuTreeselect(@PathVariable("roleId") Long roleId) {
		return menuService.roleMenuTreeselect(roleId);
	}

    /**
     * 新增菜单权限
     */
    @PostMapping
    @RequiresPermissions("system:menu:add")
    @Log(title = "菜单权限", businessType = BusinessType.INSERT)
    public int add(@RequestBody SysMenu sysMenu) {
    	return menuService.add(sysMenu);
    }

    /**
     * 修改菜单权限
     */
    @PutMapping
    @RequiresPermissions("system:menu:edit")
    @Log(title = "菜单权限", businessType = BusinessType.UPDATE)
    public int edit(@RequestBody SysMenu sysMenu) {
        return menuService.edit(sysMenu);
    }

    /**
     * 删除菜单权限
     */
	@DeleteMapping("/{menuId}")
    @RequiresPermissions("system:menu:remove")
    @Log(title = "菜单权限", businessType = BusinessType.DELETE)
    public int remove(@PathVariable("menuId") Long menuId){
        return menuService.remove(menuId);
    }
}